package com.example.app03.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.app03.App03Application;
import com.example.app03.bean.Category;
import com.example.app03.service.ICategoryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/category")
@RestController
@Api(description = "栏目管理")
public class CategoryController {
	@Autowired
	private ICategoryService categoryService;
	
	@PostMapping("/saveOrUpdate")
	@ApiOperation(value = "保存或更新栏目信息",notes = "如果id为空是保存，否则为空")
	public String saveOrUpdate(Category category) {
		categoryService.saveOrUpdate(category);
		return "更新成功";
		
	}
	
	@ApiOperation("查询所有栏目信息")
	@GetMapping("findAll")
	public List<Category> findAll(){
		return categoryService.findAll();
	}
	@ApiOperation("根据id查询栏目信息")
	@GetMapping("findById")
	@ApiImplicitParam(name = "id",value = "栏目id",required = true,dataType = "long",paramType = "")
	public Category findById(long id) {
		return categoryService.findById(id);
		
	}
	
	@GetMapping("deleteById")
	public String deleteById(long id) {
	   categoryService.deleteById(id);
		return "删除成功";
		
	}
	
	}
	
	
	
